package com.gj.subclass.mapper;

import com.gj.subclass.model.SubClassAddVo;
import com.gj.subclass.model.SubClassSelectVo;
import com.gj.subclass.model.SubClassUpdateVo;
import com.gj.subclass.model.SubClassVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by Tangyunhen on 2021-06-24.
 */
@Mapper
public interface SubClassMapper {
    List<SubClassVo> queryData(SubClassSelectVo subClassSelectVo);

    int queryCount(SubClassSelectVo subClassSelectVo);

    @Select("select count(id) from subclass where name = #{name}")
    int queryByName(@NotBlank(message = "名字不能为空") String name);

    @Select("select *from subclass where code =#{code}")
    SubClassVo queryByCode(@NotNull(message = "编码不能为空") String code);

    @Insert("insert into subclass (name,code,remark,status) value (#{name},#{code},#{remark},#{status})")
    void insert(SubClassAddVo subClassAddVo);

    @Select("select * from subclass where id = #{id}")
    SubClassVo queryById(@NotNull(message = "id不能为空") Integer id);

    @Update("update subclass set name=#{name},remark=#{remark},status =#{status} where id =#{id}")
    void update(@Valid SubClassUpdateVo subClassUpdateVo);

    @Update("update subclass set status =#{status} where id =#{id}")
    void updateStatus(SubClassVo subClassVo);
}
